/* eslint-disable @typescript-eslint/no-explicit-any */
import { Suspense } from "react";
import routes from "./router/Router";
import { Route, Routes, Navigate, BrowserRouter } from "react-router-dom";

const App = () => {
  const renderRouter = (routes: any[]) => {
    return (
      routes &&
      routes.map((item) => {
        return (
          <Route
            path={item.path}
            key={item.path}
            element={
              item.to ? (
                <Navigate to={item.to}></Navigate>
              ) : (
                <Suspense>
                  <item.element></item.element>
                </Suspense>
              )
            }
          >
            {item.children && renderRouter(item.children)}
          </Route>
        );
      })
    );
  };

  return (
    <BrowserRouter>
      <Routes>{renderRouter(routes)}</Routes>
    </BrowserRouter>
  );
};

export default App;
